import axios from "axios";
import axiosRetry from "axios-retry";

const instance = axios.create({
    baseURL: '/api',
    timeout: 20000
})

axiosRetry(instance, {
    retries: 3,
    retryDelay: (retryCount) => {
        return retryCount * 1000
    }
})

// 添加请求拦截器
instance.interceptors.request.use((config) => {
    console.log(config, "config")
    const access =localStorage.getItem('access');
    config.headers.Authorization = 'Bearer' + access
    return config;
}, (error) => {
    return Promise.reject(error);
});


// 添加响应拦截器
instance.interceptors.response.use((response) => {

    console.log(response, "response")
    return response.data;
}, (error) => {
    return Promise.reject(error);
});

const postWay = (url, data) => {
    return instance.post(url, data);
}

const getWay = (url) => {
    return instance.get(url);
}

const deleteWay = (url, data) => {
    return instance.delete(url, data);
}

const putWay = (url, data) => {
    return instance.put(url, data);
}

export default { postWay, deleteWay, getWay, putWay };